package com.zktr.dao;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.zktr.bean.AdminBean;
import com.zktr.pojo.Brand;
import com.zktr.utils.CRUDDAO;

public class BrandDao {
	CRUDDAO<Brand> crud = new CRUDDAO<>(Brand.class);   
	public static void main(String[] args) {
		BrandDao gDao = new BrandDao();
		/*List<Brand> qAllBrand = gDao.queryAllBrand(1,5);
		for (Brand brand : qAllBrand) {
			System.out.println(brand);
		}*/
		
	Brand brand=new Brand();
	brand.setBrandid(19);
	brand.setBrandlogo("12");
	brand.setBrandname("ss");
	brand.setSortorder(50);
		brand.setBranddesc("1");
		brand.setIsshow(true);
		int addBrand = gDao.addBrand(brand);
	 System.out.println(addBrand);
	}
	/**
	 * 分页查询所有数据
	 * @return
	 */
	public List<Brand> queryAllBrand(int pc,int ps){
    	   LinkedHashMap<String, Object[]> map = new LinkedHashMap<String,Object[]>();
    	   map.put("select * from Brand limit ?,?", new Object[]{(pc-1)*ps,ps});
    	   return crud.selectAll(map).get(0);
       }
	/**
	 * 
	 * 查询所有记录数
	 * 
	 * @return
	 */
	public int  selectBrandCount() {
		return crud.selectCount("select count(*) from Brand");
	}

	/**
	 * 查询某一类商品中存在的品牌
	 * @return 
	 */
	public List<Brand> selectBraandByCatid(int catid) {
		return crud.select("select * from brand where brandid in(select DISTINCT brandid from goods where catid=?)", catid);
	}
	public List<Brand> queryAllBrandId(int parseInt) {
		return crud.select("select * from brand where brandid=?", parseInt);
	}
	/**
	 * 更新品牌信息
	 * @param goods
	 * @param id
	 * @return
	 */
	public int updateBrand(Brand adBean,int id) {
		Map<String,Object []> map=new LinkedHashMap<String,Object []> ();
		map.put("update brand set brandname=?,branddesc=?,sortorder=?,isshow=? where brandid=?", 
				new Object[]{adBean.getBrandname(),adBean.getBranddesc(),adBean.getSortorder(),adBean.getIsshow(),id});
		 return crud.updateAll(map)[0];
	}
	public int updateBrandlogo(Brand brand, int id) {
		Map<String,Object []> map=new LinkedHashMap<String,Object []> ();
		map.put("update brand set brandlogo=? where brandid=?", 
				new Object[]{brand.getBrandlogo(),id});
		 return crud.updateAll(map)[0];
	}
	/**
	 * 根据管理员id删除管理员
	 * @param id
	 * @return
	 */
	public int deleteOneBrandId(int id) {
		Map<String,Object []> map=new LinkedHashMap<String,Object []> ();
		map.put("delete from brand where brandid=? ",new Object[]{id});
		 return crud.updateAll(map)[0];
	}
	/**
	 * 新增一个品牌
	 * @param brand
	 * @return
	 */
	public int addBrand(Brand brand) {
		Map<String,Object []> map=new LinkedHashMap<String,Object []> ();
		map.put("insert into brand values(?,?,?,?,?,?) ",new Object[]{
        brand.getBrandid(),brand.getBrandname(),brand.getBrandlogo(),brand.getBranddesc(),
        brand.getSortorder(),brand.getIsshow()
		});
		 return crud.updateAll(map)[0];
	}

	
}
